﻿<!--包含头部文件-->
{include file="public/header" /}
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 轮播管理 <span class="c-gray en">&gt;</span> 轮播列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-10">
		<span class="l">
			<a href="javascript:;" onclick="carousel_add('新增轮播','{:url(\'operate/carousel_add\')}',$(window).width()*0.6,$(window).height()*0.7)" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增轮播</a>
		</span>
		<span class="r">共有数据：<strong>{$total}</strong> 条</span>
	</div>
	<form class="form form-horizontal" name="ruleorder" method="post" action="" id="ajaxForm">
	<table class="table table-border table-bordered table-bg">
		<thead>
		<tr>
			<th scope="col" colspan="13">轮播列表</th>
		</tr>
		<tr class="text-c">
			<th width="15%">封面图</th>
			<th width="15%">标题</th>
			<th>类型</th>
			<th>展示位置</th>
			<th>开始时间</th>
			<th>结束时间</th>
			<th>是否启用</th>
			<th>创建时间</th>
			<th>排序</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
		{volist name="list" id="v"}
		<tr class="text-c">
			<td>
				<img src="{$v.image}" width="336" height="80">
			</td>
			<td>{$v.title}</td>
			<td>
				{if condition="$v['cate'] == 1 "} 店铺
				{elseif condition="$v['cate'] == 2"}网页
				{elseif condition="$v['cate'] == 3"}专题
				{else /}商品
				{/if}
			</td>
			<td>
				{if condition="$v['position'] == 1 "} 首页顶部
				{elseif condition="$v['position'] == 2"}首页中部
				{elseif condition="$v['position'] == 3"}好货页面
				{/if}
			</td>
			<td>{$v.start_time|date="Y-m-d H:i:s", ###}</td>
			<td>{$v.end_time|date="Y-m-d H:i:s", ###}</td>
			<td>
				{if condition="$v['status'] == 1 "}<i class="Hui-iconfont" style="color: #0AB025">&#xe6a7;</i>
				{else /} <i class="Hui-iconfont" style="color: red">&#xe6a6;</i>
				{/if}
			</td>
			<td>{$v.add_time|date="Y-m-d H:i:s", ###}</td>
			<td><input name="{$v.carousel_id}" value="{$v.sort}" style="width: 50px;"/></td>
			<td class="td-manage">
				<a title="编辑" href="javascript:;" onclick="carousel_edit('轮播编辑','{:url(\'operate/carousel_edit\',[\'carousel_id\'=>$v.carousel_id])}','800','500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
				{if condition="$v['cate'] == 3 "}
				<a title="关联商品" href="javascript:;" onclick="subject_items('关联商品','{:url(\'operate/subject_items\',[\'subject_id\'=>$v.carousel_id])}',$(window).width(),$(window).height())" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe667;</i></a>
				{/if}
				<a title="删除" href="javascript:;" onclick="carousel_del(this,'{$v.carousel_id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
			</td>
		</tr>
		{/volist}
		<tr>
			<td colspan="10" align="left">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;排序&nbsp;&nbsp;">
				<span align="right">按数值从小到大排序</span>
			</td>

		</tr>
		</tbody>
	</table>
	</form>
	<div class="row">
		<div class="col-sm-2" id="pageBox">
			{$page}
		</div>
	</div>
</div>
<!--包含footer文件-->
{include file="public/footer" /}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__STATIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__STATIC__/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
	/*
	 参数解释：
	 title 标题
	 url      请求的url
	 id       需要操作的数据id
	 w    弹出层宽度（缺省调默认值）
	 h    弹出层高度（缺省调默认值）
	 */
	/*轮播-增加*/
	function carousel_add(title,url,w,h){
		layer_show(title,url,w,h);
	}

    /*专题关联商品-列表*/
    function subject_items(title,url,w,h){
        layer_show(title,url,w,h);
    }

	/*轮播-删除*/
	function carousel_del(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: 'POST',
				url: '{:url("operate/carousel_del")}',
                data:{"carousel_id":id},
				dataType: 'json',
				success: function(data){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:1,time:1000});
				},
				error:function(data) {
					console.log(data.msg);
				},
			});

		});
	}

	/*轮播-编辑*/
	function carousel_edit(title,url,w,h){
		layer_show(title,url,w,h);
	}
	/*店铺-停用*/
	function admin_stop(obj,id){
		layer.confirm('确认要停用吗？',function(index){
			//此处请求后台程序，下方是成功后的前台处理……
			$.post("admin/change_admin",'',function(result){
				console.log(result)
			});

			$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,id)" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
			$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
			$(obj).remove();
			layer.msg('已停用!',{icon: 5,time:1000});
		});
	}

	/*管理员-启用*/
	function admin_start(obj,id){
		layer.confirm('确认要启用吗？',function(index){
			//此处请求后台程序，下方是成功后的前台处理……


			$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,id)" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
			$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
			$(obj).remove();
			layer.msg('已启用!', {icon: 6,time:1000});
		});
	}

    $(function () {
        // 排序
        $("#ajaxForm").validate({
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var arr = new FormData(document.getElementById("ajaxForm"));
                $.ajax({
                    url:"{:url('operate/carousel_order')}",
                    type:"post",
                    data:arr,
                    async: true,
                    processData: false,
                    contentType: false,
                    dataType:"json",
                    success:function (data) {
                        if (data.code == 200){
                            layer.alert('排序成功',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                                ,yes:function(){
                                    location.reload();
                                }
                            })
                        }else {
                            layer.alert('排序失败'+data.msg+'',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                            })
                        }

                    },
                    error:function () {
                        layer.alert('排序失败',{
                            skin: 'layui-layer-molv' //样式类名 自定义样式
                            ,closeBtn: 0  // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: '确认'//按钮
                            ,icon: 6  // icon
                        })
                    }
                })

            }
        });
    })

</script>
</body>
</html>
